﻿
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Text;

namespace Moonwish.Core
{
    /// <summary>
    /// 查询条件
    /// </summary>
    [DataContract]
    public class Request
    {
        #region 构造函数

        /// <summary>
        /// 
        /// </summary>
        public Request()
        {
            Items = new List<Condition>();
            Pagination = new Pagination();
        }
        #endregion

        #region 属性
        /// <summary>
        /// 查询条件
        /// </summary>
        [DataMember]
        public List<Condition> Items
        {
            get;
            set;
        }

        /// <summary>
        /// 分页
        /// </summary>
        [DataMember]
        public Pagination Pagination
        {
            get;
            set;
        }

        /// <summary>
        /// 操作人
        /// </summary>
        [DataMember]
        public string Who { get; set; }

        /// <summary>
        /// 查询什么
        /// </summary>
        [DataMember]
        public string What { get; set; }

        #endregion

        #region GetHashCode

        /// <summary>
        /// 返回当前实例的哈希代码
        /// </summary>
        /// <returns></returns>
        public new string GetHashCode()
        {
            var ms = new MemoryStream();
            var serializer = new DataContractSerializer(typeof(Request));
            serializer.WriteObject(ms, this);
            var array = ms.ToArray();
            ms.Close();

            return Md5.GetHashString(array);
        }

        #endregion

    }
}
